/**
 * Created by Denvey on 2014/10/20.
 */
$(function(){

    var hospitalData = receive(getHospital());
    var typeData = [
        {
            "name": "MV-机械瓣膜",
            "typeId": 1
        },
        {
            "name": "TV-生物瓣膜",
            "typeId": 2
        },
        {
            "name": "Valve Repair-成型环",
            "typeId": 3
        }
    ];

    var companyData = [
        {
            "companyId": 1,
            "name": "Medtronic"
        },
        {
            "companyId": 1,
            "name": "Medtronic"
        }
    ];

    var productData = [{
            "productId":1,
            "name":" ATS STD",
            "count":10
        },{
            "productId":2,
            "name":" ATS AP",
            "count":12
        }
    ];



    var hospitalId = -1,
        typeId = -1,
        companyId = -1;

    var homeData = {
        data:{
            "back":0,
            "slideNum":1,
            "list":hospitalData
        }
    }
    var homeTemp = template("homeTemp",homeData);
    $("#wrapper").empty().append(homeTemp);

    var $document = $(document),
        slideListTemp = template("slideTemp"),
        $slideWrapper = $(".slide-wrapper");

    $document.on("click",".slide1 a",function(){
        var data = {
            "back":1,
            "slideNum":2,
            "list":typeData
        };
        var $slide = $(".slide"); 
        $slide.eq(0).hide();
        $slide.eq(1).hide();
        hospitalId = $(this).data("id");
        $slideWrapper.append(template("typeTemp",data));
    });

    $document.on("click",".slide2 a",function(){
        var data = {
            "back":1,
            "slideNum":3,
            "list":companyData
        };
        var $slide = $(".slide"); 
        $slide.eq(1).hide();
        $slide.eq(2).hide();
        $slideWrapper.append(template("companyTemp",data));
        typeId = $(this).data("id");
    });


    $document.on("click",".slide3 a",function(){
        var data = {
            "back":1,
            "slideNum":4,
            "list":productData
        };
        var $slide = $(".slide"); 
        $slide.eq(2).hide();
        $slide.eq(3).hide();
        companyId = $(this).data("id");
        $slideWrapper.append(template("companyTemp",data));
        contentTemp();
    });

    $document.on("click",".slide4 a",function(){
        contentTemp();
    });

    function contentTemp(hospitalId,typeId,companyId){
        var data = {
            "list":productData
        }
        $(".content-wrapper").empty().append(template("content-r",data));
    }

    $document.on("click",".arrow_l",function(){
        var that = $(this).next();
        that.text(parseInt(that.text()) - 1);
    });
    $document.on("click",".arrow_r",function(){
        var that = $(this).prev();
        that.text(parseInt(that.text()) + 1);
    });
});